<?php
namespace App\Api\Controllers;

use Illuminate\Support\Facades\DB;

use App\Api\Controllers\BaseController;
use App\Models\Sys\SysSetting;
use App\Models\User\UserFunds;
use App\Models\User\Users;
use Illuminate\Http\Request;

use App\Api\Service\UserService;

class UserController extends BaseController{
    protected $service;

    public function __construct(Request $request){
        parent::__construct($request);
        $this->service = new UserService();
    }

    public function detail(Request $request){
        $number = $request->input('number', '');
        return ['code'=> 200, 'msg'=> '会员详情', 'data'=> $this->service->use_id_get_data($this->uid, $number)];
    }

    /**
     * 更新红点为已读
     *
     * @param \App\Api\Requests\User\RedDotRequest $request
     * @return void
     */
    public function set_red_dot(\App\Api\Requests\User\RedDotRequest $request){
        $type = $request->input('type');
        $res = $this->service->set_red_dot($this->uid, $type);
        return $res ? success('更新成功') : error('更新失败');
    }

    /**
     * 编辑资料
     *
     * @param \App\Api\Requests\User\UpdateDetailRequest $request
     * @return void
     */
    public function update_detail(\App\Api\Requests\User\UpdateDetailRequest $request){
        $data = [
            'user_detail'=> [
                'general_photo'=> $request->input('general_photo', '') ?? '',
                'life_photo'=> $request->input('life_photo', '') ?? '',
                'work_photo'=> $request->input('work_photo', '') ?? '',
                'study_photo'=> $request->input('study_photo', '') ?? '',
                'travel_photo'=> $request->input('travel_photo', '') ?? '',
                'other_photo'=> $request->input('other_photo', '') ?? '',
                'sex'=> $request->input('sex', ''),
                'birthday'=> $request->input('birthday', ''),
                'face_score'=> $request->input('face_score', ''),
                'constellation'=> $request->input('constellation', '') ?? '',
                'height'=> $request->input('height', ''),
                'weixin'=> $request->input('weixin', '') ?? '',
                'qq'=> $request->input('qq', '') ?? '',
                'email'=> $request->input('email', '') ?? '',
                'city'=> $request->input('city', ''),
                'hometown'=> $request->input('hometown', ''),
                'education'=> $request->input('education', ''),
                'college'=> $request->input('college', ''),
                'college_tab'=> $request->input('college_tab', '') ?? '',
                'income'=> $request->input('income', ''),
                'marriage'=> $request->input('marriage', ''),
                'car_and_house'=> $request->input('car_and_house', '') ?? '',
                'car_and_house_detail'=> $request->input('car_and_house_detail', '') ?? '',
                'family'=> $request->input('family', '') ?? '',
                'account'=> $request->input('account', '') ?? '',
                'industry'=> $request->input('industry', '') ?? '',
                'hobbies'=> $request->input('hobbies', '') ?? '',
                'character'=> $request->input('character', '') ?? '',
                'emotional_experience'=> $request->input('emotional_experience', '') ?? '',
                'emotional_view'=> $request->input('emotional_view', '') ?? '',
                'mate_selection'=> $request->input('mate_selection', '') ?? '',
                'other'=> $request->input('other', '') ?? '',
                'keyword'=> $request->input('keyword', '') ?? '',
            ],
            'user'=> [
                'nickname'=> $request->input('nickname', ''),
            ]
        ];
        return success('更新成功', $this->service->update_detail($this->uid, $data));
    }

    /**
     * 获取会员详细信息（相亲名片）
     *
     * @return void
     */
    public function visiting_card(){
        return success('名片', $this->service->get_user_detail($this->uid));
    }

    /**
     * 获取会员积分相关信息
     *
     * @return void
     */
    public function integrate(){
        return success('会员积分', $this->service->get_integrate_data($this->uid));
    }

    /**
     * 根据会员id查询会员信息
     *
     * @param \App\Api\Requests\User\SearchIdRequest $request
     * @return void
     */
    public function search_id(\App\Api\Requests\User\SearchIdRequest $request){
        $id = $request->input('id');
        return success('会员详情', $this->service->get_user_detail($id, $this->uid));
    }
}
